package com.xmsx.back.mapper.admin;

import com.xmsx.back.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 获得用户信息
     *
     * @param username
     * @return
     */
    @Select("select * from administrator where username = #{username}")
    User getByUsername(@Param("username") String username);

    /**
     * 插入用户信息
     *
     * @param user
     */
    @Insert("insert into administrator (username, password) " +
            "values (#{user.username}, #{user.password} )")
    void setUser(@Param("user") User user);

    /**
     * 删除账户
     *
     * @param username
     */
    @Select("delete from administrator where username = #{username}")
    void deleteUser(@Param("username") String username);

    /**
     * 获取所有管理员
     *
     * @return
     */
    @Select("select username from administrator ")
    List<User> getAllUsers();

    /**
     * 更新用户信息
     *
     * @param user
     */
    @Select("update administrator set password = #{user.password} where username = #{user.username} ")
    void updateUser(@Param("user") User user);
}